package com.py.longtrans.util;

import com.py.longtrans.LongTrans;
import com.py.longtrans.excel.ExcelUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimerTask;

public class TimeTask extends TimerTask {

    // 每天4点传前一天的
    private static String taskTime = "08:55";
    private static Logger logger = LoggerFactory.getLogger(TimeTask.class);
    @Override
    public void run() {
        logger.info("日传任务");
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String s = df.format(new Date());// new Date()为获取当前系统时间
        String s1 = s.split(" ")[1];
        String s2 = s1.substring(0,s1.lastIndexOf(":"));
        System.out.println(s2);
        logger.info("时间为："+s2);
        if (s2.equals(taskTime)){
//        if(true){
            logger.info("日传开始！");
            try {
//                LongTrans.transFile("/tmp/D_006_F10004_006_68903_20220329_00.chk"); // 测试
//                LongTrans.transFile("/tmp/D_006_F10004_006_68903_20220329_00.txt"); // 测试
                ExcelUtil.ProcessIn();
            }
            catch (IOException | SQLException e) {
                e.printStackTrace();
                logger.error(e.toString());
            }
        }

    }
}
